defmodule BeerSong do
  @doc """
  Get a single verse of the beer song
  """
  @spec verse(integer) :: String.t()

  def verse(number) when number >= 0 do
    # inter.function to printing the number or "no more"
    qty = fn
      0 -> "no more"
      x -> x
    end

    # inter.function to determine tail s
    s = fn
      1 -> ""
      _ -> "s"
    end

    how_many = fn n -> "#{qty.(n)} bottle#{s.(n)} of beer" end
    how_many_next = fn 
      0 -> how_many.(99) 
      x -> how_many.(x-1)
    end

    # function to print what to do
    action = fn
      0 -> "Go to the store and buy some more"
      1 -> "Take it down and pass it around"
      _ -> "Take one down and pass it around"     
    end

    """
    #{String.capitalize(how_many.(number))} on the wall, #{how_many.(number)}.
    #{action.(number)}, #{how_many_next.(number)} on the wall.
    """
  end
  
  #def verse(number) do
  #  # Your implementation here...
  #end

  @doc """
  Get the entire beer song for a given range of numbers of bottles.
  """
  @spec lyrics(Range.t()) :: String.t()
  def lyrics(range \\ 99..0) do
    # Your implementation here...
    Enum.map_join(range, "\n", &verse(&1))
  end
end
